<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
$(function(){
	$('form').submit(function(){
		var product_data = encodeURIComponent($('#product_data').val());
		var start_warehouse_id = $('#start_warehouse').val();
		var end_warehouse_id = $('#end_warehouse').val();
		var submit = true;
		if (!start_warehouse_id || !end_warehouse_id)
		{
			alert("调拨仓和目标仓不能为空！");
			return false;
		}
		if (start_warehouse_id == end_warehouse_id)
	  	{
	  		alert("调拨仓和目标仓不能相同！");
		  	return false;
	  	}
		if (!product_data)
		{
			alert("请填写调拨产品数据 ！");
			return false;
		}
		$.ajax({
			url:"<?=url('Storage::Allocate/CheckAvailableQuantity')?>&product_data="+product_data+"&start_warehouse_id="+start_warehouse_id+"&end_warehouse_id="+end_warehouse_id,
			dataType: 'json',
			async: false,
			success:
				function(data)
				{
					if (data != '')
					{
						var _html = '';
						$.each(data, function(i, product){
							_html += '<p><span class=\'red\'>' + product + '</span></p>';
						});
						$("#wrong_product").html(_html);
						submit = false;
					}
				}
		});
	  	return submit;
	});
})
</script>

<form method="post" action="<?=url('Storage::Allocate/CreateSave')?>">
<table class="form_table">
	<tr>
		<th>起始仓</th>
		<td>
			<select name="start_warehouse_id" id="start_warehouse">
				<option value="">请选择···</option>
				<?foreach ($warehouse as $w):?>
				<option value="<?=$w['id']?>"><?=$w['name']?></option>
				<?endforeach;?>
			</select>
		</td>
		<th>目标仓</th>
		<td>
			<select name="end_warehouse_id" id="end_warehouse">
				<option value="">请选择···</option>
				<?foreach ($warehouse as $w):?>
				<option value="<?=$w['id']?>"><?=$w['name']?></option>
				<?endforeach;?>
			</select>
		</td>
	</tr>
	<tr>
		<th>备注</th>
		<td colspan="3"><textarea rows="4" cols="50" name="notes"><?=isset($order['notes']) ? $order['notes'] : ''?></textarea></td>
	</tr>
	<tr>
		<td colspan="4">说明：产品编号和数量用逗号（半角英文逗号） 为一条记录，每条记录用回车分开</td>
	</tr>
	<tr>
		<th>产品</th>
		<td colspan="3"><textarea cols="50" rows="20" name="product_data" id="product_data"></textarea></td>
		<td id="wrong_product"></td>
	</tr>
	<tr>
		<td><input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/></td>
		<td colspan="3"><input type="submit" class="button" value="添加调拨单" /><span class="red">*注意调拨产品所在的仓库*</span></td>
	</tr>
</table>
</form>
<?php $this->_endblock();?>